package com.javaweb.controller.common;

import com.javaweb.service.dto.ArticleDto;
import com.javaweb.service.dto.PageResult;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.util.stream.Collectors;

/**
 * @desc:
 * @author: Ping
 * @date: 2024/10/22 16:26
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Accessors(chain = true)
public class ArticleVo {
    private String title;
    private String content;
    private String authorName;
    //@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private String createTime;
    //@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private String updateTime;
    private String status;
    private String categoryName;
    private String tags;
    private String recommended ;
    private String isTop ;

    private String viewCount ;
    private String suppCount ;



    public static ArticleVo toArticleVo(ArticleDto articleDto) {
        return ArticleVo.builder()
                .title(articleDto.getTitle())
                .content(articleDto.getContent())
                .authorName(articleDto.getAuthorName())
                .createTime(articleDto.getCreateTime())
                .updateTime(articleDto.getUpdateTime())
                .status(articleDto.getStatus())
                .categoryName(articleDto.getCategoryName())
                .tags(articleDto.getTags())
                .suppCount(articleDto.getSuppCount())
                .viewCount(articleDto.getViewCount())
                .isTop((articleDto.isTop() == true ? "是" : "否"))
                .recommended((articleDto.isRecommended() == true ? "是" : "否"))
                .build();

    }

    public static PageResult<ArticleVo> toArticleVo(PageResult<ArticleDto> articleDtoPageResult) {
        return PageResult.<ArticleVo>builder()
                .data(articleDtoPageResult.getData().stream().map(ArticleVo::toArticleVo).collect(Collectors.toList()))
                .pageNum(articleDtoPageResult.getPageNum())
                .pageSize(articleDtoPageResult.getPageSize())
                .build();
    }


}
